import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.Toolkit;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

public class ConverterGUI {

	private JFrame jFrame = null;
	private JPanel jContentPane = null;
	private JPanel jPanel = null;
	private JLabel fromLabel = null;
	private JLabel toLabel = null;
	private JLabel amountLabel = null;
	private JButton fromButton = null;
	private JButton toButton = null;
	private String to = "";
	private String from = "";
	private JTextField amountTextField = null;
	private JButton convertButton = null;
	private JLabel resultLabel = null;
	private JLabel result = null;
	private Converter c;
	private Double d;
	private JDialog selectorDialog = null;
	private JPanel selectorContentPane = null;
	private JPanel selectorPanel = null;
	private JButton toUSDButton = null;
	private JButton toILSButton = null;
	private JButton toEuroButton = null;
	private JButton toYenButton = null;
	private JButton toCADButton = null;
	private JDialog selectorDialogFrom = null;
	private JPanel selectorContentPane1 = null;
	private JPanel selectorPanel1 = null;
	private JButton toUSDButton1 = null;
	private JButton toILSButton1 = null;
	private JButton toEuroButton1 = null;
	private JButton toYenButton1 = null;
	private JButton toCADButton1 = null;
	/**
	 * This method initializes jFrame
	 * 
	 * @return javax.swing.JFrame
	 */
	private JFrame getJFrame() {
		if (jFrame == null) {
			c = new Converter();
			jFrame = new JFrame();
			jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			jFrame.setSize(521, 178);
			jFrame.setContentPane(getJContentPane());
			jFrame.setTitle("Currency Converter");
			Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
			Point p = new Point((((screenSize.width)/2)-(jFrame.getWidth())/2), (((screenSize.height)/2)-(jFrame.getHeight())/2));
			jFrame.setLocation(p);
		}
		return jFrame;
	}

	/**
	 * This method initializes jContentPane
	 * 
	 * @return javax.swing.JPanel
	 */
	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jContentPane = new JPanel();
			jContentPane.setLayout(new BorderLayout());
			jContentPane.add(getJPanel(), BorderLayout.CENTER);
		}
		return jContentPane;
	}

	/**
	 * This method initializes jPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getJPanel() {
		if (jPanel == null) {
			result = new JLabel();
			result.setBounds(new Rectangle(360, 60, 121, 31));
			result.setText("");
			resultLabel = new JLabel();
			resultLabel.setBounds(new Rectangle(255, 60, 91, 31));
			resultLabel.setText("Result:");
			amountLabel = new JLabel();
			amountLabel.setText("Amount:");
			amountLabel.setBounds(new Rectangle(255, 15, 91, 31));
			toLabel = new JLabel();
			toLabel.setText("To Currency:");
			toLabel.setBounds(new Rectangle(15, 60, 91, 31));
			fromLabel = new JLabel();
			fromLabel.setText("From Currency:");
			fromLabel.setBounds(new Rectangle(15, 15, 91, 31));
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.add(fromLabel, null);
			jPanel.add(toLabel, null);
			jPanel.add(amountLabel, null);
			jPanel.add(getFromButton(), null);
			jPanel.add(getToButton(), null);
			jPanel.add(getAmountTextField(), null);
			jPanel.add(getConvertButton(), null);
			jPanel.add(resultLabel, null);
			jPanel.add(result, null);
		}
		return jPanel;
	}

	/**
	 * This method initializes fromButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getFromButton() {
		if (fromButton == null) {
			fromButton = new JButton();
			fromButton.setBounds(new Rectangle(120, 15, 121, 31));
			fromButton.setText("Select...");
			fromButton.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					getSelectorDialogFrom().setVisible(true);
					Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
					Point p = new Point((((screenSize.width)/2)-(selectorDialogFrom.getWidth())/2), (((screenSize.height)/2)-(selectorDialogFrom.getHeight())/2));
					selectorDialogFrom.setLocation(p);
				}
			});
		}
		return fromButton;
	}

	/**
	 * This method initializes toButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getToButton() {
		if (toButton == null) {
			toButton = new JButton();
			toButton.setText("Select...");
			toButton.setBounds(new Rectangle(120, 60, 121, 31));
			toButton.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					getSelectorDialog().setVisible(true);
					Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
					Point p = new Point((((screenSize.width)/2)-(selectorDialog.getWidth())/2), (((screenSize.height)/2)-(selectorDialog.getHeight())/2));
					selectorDialog.setLocation(p);
				}
			});
		}
		return toButton;
	}

	/**
	 * This method initializes amountTextField	
	 * 	
	 * @return javax.swing.JTextField	
	 */
	private JTextField getAmountTextField() {
		if (amountTextField == null) {
			amountTextField = new JTextField();
			amountTextField.setBounds(new Rectangle(360, 15, 121, 31));
		}
		return amountTextField;
	}

	/**
	 * This method initializes convertButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getConvertButton() {
		if (convertButton == null) {
			convertButton = new JButton();
			convertButton.setBounds(new Rectangle(150, 105, 196, 31));
			convertButton.setText("Convert!");
			convertButton.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					d = c.convert(new Double(getAmountTextField().getText()).intValue(), from, to);
					String str = "" + d;
					result.setText(str);
				}
			});
		}
		return convertButton;
	}

	/**
	 * This method initializes selectorDialog	
	 * 	
	 * @return javax.swing.JDialog	
	 */
	private JDialog getSelectorDialog() {
		if (selectorDialog == null) {
			selectorDialog = new JDialog(getJFrame());
			selectorDialog.setSize(new Dimension(179, 195));
			selectorDialog.setTitle("Select To...");
			selectorDialog.setContentPane(getSelectorContentPane());
		}
		return selectorDialog;
	}

	/**
	 * This method initializes selectorContentPane	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getSelectorContentPane() {
		if (selectorContentPane == null) {
			selectorContentPane = new JPanel();
			selectorContentPane.setLayout(new BorderLayout());
			selectorContentPane.add(getSelectorPanel(), BorderLayout.CENTER);
		}
		return selectorContentPane;
	}

	/**
	 * This method initializes selectorPanel	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getSelectorPanel() {
		if (selectorPanel == null) {
			selectorPanel = new JPanel();
			selectorPanel.setLayout(null);
			selectorPanel.add(getToUSDButton(), null);
			selectorPanel.add(getToILSButton(), null);
			selectorPanel.add(getToEuroButton(), null);
			selectorPanel.add(getToYenButton(), null);
			selectorPanel.add(getToCADButton(), null);
		}
		return selectorPanel;
	}

	/**
	 * This method initializes toUSDButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getToUSDButton() {
		if (toUSDButton == null) {
			toUSDButton = new JButton();
			toUSDButton.setBounds(new Rectangle(13, 15, 65, 38));
			toUSDButton.setText("USD");
			toUSDButton.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					to = "USD";
					toButton.setText(to);
					selectorDialog.setVisible(false);
				}
			});
		}
		return toUSDButton;
	}

	/**
	 * This method initializes toILSButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getToILSButton() {
		if (toILSButton == null) {
			toILSButton = new JButton();
			toILSButton.setBounds(new Rectangle(15, 60, 65, 38));
			toILSButton.setText("ILS");
			toILSButton.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					to = "ILS";
					toButton.setText(to);
					selectorDialog.setVisible(false);
				}
			});
		}
		return toILSButton;
	}

	/**
	 * This method initializes toEuroButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getToEuroButton() {
		if (toEuroButton == null) {
			toEuroButton = new JButton();
			toEuroButton.setBounds(new Rectangle(90, 60, 65, 38));
			toEuroButton.setText("Euro");
			toEuroButton.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					to = "EURO";
					toButton.setText(to);
					selectorDialog.setVisible(false);
				}
			});
		}
		return toEuroButton;
	}

	/**
	 * This method initializes toYenButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getToYenButton() {
		if (toYenButton == null) {
			toYenButton = new JButton();
			toYenButton.setBounds(new Rectangle(90, 15, 65, 38));
			toYenButton.setText("Yen");
			toYenButton.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					to = "YEN";
					toButton.setText(to);
					selectorDialog.setVisible(false);
				}
			});
		}
		return toYenButton;
	}

	/**
	 * This method initializes toCADButton	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getToCADButton() {
		if (toCADButton == null) {
			toCADButton = new JButton();
			toCADButton.setBounds(new Rectangle(15, 105, 65, 38));
			toCADButton.setText("CAD");
			toCADButton.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					to = "CAD";
					toButton.setText(to);
					selectorDialog.setVisible(false);
				}
			});
		}
		return toCADButton;
	}

	/**
	 * This method initializes selectorDialogFrom	
	 * 	
	 * @return javax.swing.JDialog	
	 */
	private JDialog getSelectorDialogFrom() {
		if (selectorDialogFrom == null) {
			selectorDialogFrom = new JDialog(getJFrame());
			selectorDialogFrom.setSize(new Dimension(179, 195));
			selectorDialogFrom.setTitle("Select From...");
			selectorDialogFrom.setContentPane(getSelectorContentPane1());
		}
		return selectorDialogFrom;
	}

	/**
	 * This method initializes selectorContentPane1	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getSelectorContentPane1() {
		if (selectorContentPane1 == null) {
			selectorContentPane1 = new JPanel();
			selectorContentPane1.setLayout(new BorderLayout());
			selectorContentPane1.add(getSelectorPanel1(), BorderLayout.CENTER);
		}
		return selectorContentPane1;
	}

	/**
	 * This method initializes selectorPanel1	
	 * 	
	 * @return javax.swing.JPanel	
	 */
	private JPanel getSelectorPanel1() {
		if (selectorPanel1 == null) {
			selectorPanel1 = new JPanel();
			selectorPanel1.setLayout(null);
			selectorPanel1.add(getToUSDButton1(), null);
			selectorPanel1.add(getToILSButton1(), null);
			selectorPanel1.add(getToEuroButton1(), null);
			selectorPanel1.add(getToYenButton1(), null);
			selectorPanel1.add(getToCADButton1(), null);
		}
		return selectorPanel1;
	}

	/**
	 * This method initializes toUSDButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getToUSDButton1() {
		if (toUSDButton1 == null) {
			toUSDButton1 = new JButton();
			toUSDButton1.setBounds(new Rectangle(13, 15, 65, 38));
			toUSDButton1.setText("USD");
			toUSDButton1.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					from = "USD";
					fromButton.setText(from);
					selectorDialogFrom.setVisible(false);
				}
			});
		}
		return toUSDButton1;
	}

	/**
	 * This method initializes toILSButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getToILSButton1() {
		if (toILSButton1 == null) {
			toILSButton1 = new JButton();
			toILSButton1.setBounds(new Rectangle(15, 60, 65, 38));
			toILSButton1.setText("ILS");
			toILSButton1.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					from = "ILS";
					fromButton.setText(from);
					selectorDialogFrom.setVisible(false);
				}
			});
		}
		return toILSButton1;
	}

	/**
	 * This method initializes toEuroButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getToEuroButton1() {
		if (toEuroButton1 == null) {
			toEuroButton1 = new JButton();
			toEuroButton1.setBounds(new Rectangle(90, 60, 65, 38));
			toEuroButton1.setText("Euro");
			toEuroButton1.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					from = "Euro";
					fromButton.setText(from);
					selectorDialogFrom.setVisible(false);
				}
			});
		}
		return toEuroButton1;
	}

	/**
	 * This method initializes toYenButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getToYenButton1() {
		if (toYenButton1 == null) {
			toYenButton1 = new JButton();
			toYenButton1.setBounds(new Rectangle(90, 15, 65, 38));
			toYenButton1.setText("Yen");
			toYenButton1.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					from = "YEN";
					fromButton.setText(from);
					selectorDialogFrom.setVisible(false);
				}
			});
		}
		return toYenButton1;
	}

	/**
	 * This method initializes toCADButton1	
	 * 	
	 * @return javax.swing.JButton	
	 */
	private JButton getToCADButton1() {
		if (toCADButton1 == null) {
			toCADButton1 = new JButton();
			toCADButton1.setBounds(new Rectangle(15, 105, 65, 38));
			toCADButton1.setText("CAD");
			toCADButton1.addMouseListener(new java.awt.event.MouseAdapter() {
				public void mouseClicked(java.awt.event.MouseEvent e) {
					from = "CAD";
					fromButton.setText(from);
					selectorDialogFrom.setVisible(false);
				}
			});
		}
		return toCADButton1;
	}

	/**
	 * Launches this application
	 */
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				ConverterGUI application = new ConverterGUI();
				application.getJFrame().setVisible(true);
			}
		});
	}
}